home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Utilities Professional 1-1500
/
Utilities Professional 1-1500 (1994)(WPD)[!].iso
/
12511500
/
var1453.dms
/
var1453.adf
/
Lists
/
Example1.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-05-02
|
3KB
|
94 lines
/***********************************************************/
/* */
/* Amiga C Encyclopedia (ACE) V3.0 Amiga C Club (ACC) */
/* ------------------------------- ------------------ */
/* */
/* Book: ACM System Amiga C Club */
/* Chapter: Lists Tulevagen 22 */
/* File: Example1.c 181 41 LIDINGO */
/* Author: Anders Bjerin SWEDEN */
/* Date: 92-05-01 */
/* Version: 1.00 */
/* */
/* Copyright 1992, Anders Bjerin - Amiga C Club (ACC) */
/* */
/* Registered members may use this program freely in their */
/* own commercial/noncommercial programs/articles. */
/* */
/***********************************************************/
/* Demonstrates how to create a list with three nodes. */
/* (Not very amazing, but useful to know.) */
#include <exec/types.h>
#include <exec/lists.h> /* This file will automatically */
/* include the file "nodes.h". */
/* Declare a complete node stucture: */
struct ToDo
{
struct Node node; /* Every node must have this. */
STRPTR Wish; /* Our own data. */
};
/* Declare a list structure: */
struct List my_list;
/* Node 1: */
struct ToDo eat=
{
{ NULL, NULL, NT_UNKNOWN, 0, "Food" },
"eat breakfast"
};
/* Node 2: */
struct ToDo sleep=
{
{ NULL, NULL, NT_UNKNOWN, 0, "Sleep" },
"rest"
};
/* Node 3: */
struct ToDo drink=
{
{ NULL, NULL, NT_UNKNOWN, 0, "Food" },
"drink some nice wine"
};
main()
{
/* Initialize our list structure: */
NewList( &my_list );
/* Add three nodes: */
printf( "Adding some nodes...\n" );
AddTail( &my_list, &eat );
AddTail( &my_list, &sleep );
AddTail( &my_list, &drink );
/* Check if the list is empty or not: */
if( my_list.lh_Head->ln_Succ == NULL )
printf( "This list is empty!\n" );
else
printf( "There is one or more nodes in this list!\n" );
/* Remove all nodes from the list: */
printf( "Remove all nodes...\n" );
RemHead( &my_list, &eat );
RemHead( &my_list, &sleep );
RemHead( &my_list, &drink );
/* Note! Actually you do not remove the nodes before your */
/* program terminates, but it looks a bit nicer if you do. */
/* (If you have allocated memory for the nodes while your */
/* program was running you must of course deallocate it, */
/* and before you do that the nodes should have been */
/* removed.) */
}